package com.apps.ppt.utils;

import lombok.SneakyThrows;
import org.apache.poi.hslf.extractor.PowerPointExtractor;
import org.apache.poi.hslf.usermodel.HSLFFreeformShape;
import org.apache.poi.hslf.usermodel.HSLFShape;
import org.apache.poi.ooxml.extractor.ExtractorFactory;
import org.apache.poi.sl.usermodel.Slide;
import org.apache.poi.sl.usermodel.SlideShow;
import org.apache.poi.sl.usermodel.SlideShowFactory;
import org.apache.poi.xslf.usermodel.*;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

/**
 * 处理ppt内容
 */
public class PPtxContextHelper {

    /**
     * 读取ppt或者pptx文档的内容
     * @param path
     * @return
     */
    @SneakyThrows
    public static String readDoc(String path)
    {
        String result="";
        File file=new File(path);
        FileInputStream is = new FileInputStream(file);
        result = ExtractorFactory.createExtractor(is).getText();
        is.close();
        return result;
    }

    @SneakyThrows
    public static String readDoc(File file)
    {
        String result="";
        FileInputStream is = new FileInputStream(file);
        result = ExtractorFactory.createExtractor(is).getText();
        is.close();
        return result;
    }


}
